package stream;

import java.util.*;

/**
 * @author <a href="mailto:sjj@jianzhimao.com">mojo</a>
 * copyright (C), 2013-2022, 广州九尾信息科技有限公司
 * @date 2022/2/11 18:15
 */
public class Apple {
    private String colour;
    private int weight;
    private boolean flag;

    public String getColour() {
        return colour;
    }

    public void setColour(String colour) {
        this.colour = colour;
    }

    public int getWeight() {
        return weight;
    }

    public void setWeight(int weight) {
        this.weight = weight;
    }

    public boolean isFlag() {
        return flag;
    }

    public void setFlag(boolean flag) {
        this.flag = flag;
    }

    public Apple(String colour, int weight, boolean flag) {
        this.colour = colour;
        this.weight = weight;
        this.flag = flag;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Apple apple = (Apple) o;
        return weight == apple.weight &&
                colour.equals(apple.colour);
    }

    @Override
    public int hashCode() {
        return Objects.hash(colour, weight);
    }

    @Override
    public String toString() {
        return new StringJoiner(", ", Apple.class.getSimpleName() + "[", "]")
                .add("colour='" + colour + "'")
                .add("weight=" + weight)
                .add("flag=" + flag)
                .toString();
    }

    public static void main(String[] args) {
        List<Apple> list = new ArrayList<>();
        list.add(new Apple("红色", 111, true));
        list.add(new Apple("黄色", 122, true));
        list.add(new Apple("蓝色", 133, false));
        list.sort(Comparator.comparing(Apple::getColour));

    }
}
